package com.itheima.web;

import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/selectByIdServlet")
public class SelectByIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.接收id
        String idStr = request.getParameter("id");
        int id = Integer.parseInt(idStr);

        // 2.调用service查询 Brand
        BrandService brandService = new BrandService();
        Brand brand = brandService.selectById(id);

        // 3.将Brand存储到request
        request.setAttribute("brand", brand);

        // 4.转发到修改页面
        request.getRequestDispatcher("/updateBrand.jsp").forward(request, response);
    }
}
